<?php
class Jnd_Outils
{

    const SALT_LENGTH = 9;

    /**
     * Fonction permettant de hasher une chaine de caractère.
     *
     * @param string $plainText            
     * @param string $salt            
     * @return string
     */
    static function generateHash( $plainText, $salt = null )
    {
        if ($salt === null) {
            $salt = substr(md5(uniqid(rand(), true)), 0, self::SALT_LENGTH);
        } else {
            $salt = substr($salt, 0, self::SALT_LENGTH);
        }
        
        return $salt . sha1($salt . $plainText);
    }

    static function supprimeAccents( $chaine )
    {
        $chaine = htmlentities($chaine, ENT_NOQUOTES, 'utf-8');
        $chaine = preg_replace('#\&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring)\;#', '\1', $chaine);
        $chaine = preg_replace('#\&([A-za-z]{2})(?:lig)\;#', '\1', $chaine);
        $chaine = preg_replace('#\&[^;]+\;#', '', $chaine);
        return $chaine;
    }
}

